package com.wangchao.administrator.zenmechi.ui.fragment.homefragment;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wangchao.administrator.zenmechi.R;
import com.wangchao.administrator.zenmechi.bean.homebean.NearbyMerchantListBean;

import java.util.List;

/**
 * Created by My on 2016/10/19.
 */
public class ListmarketAdapter extends BaseAdapter {
    private List<NearbyMerchantListBean> nearbyMerchantList;
    private Context context;

    public ListmarketAdapter(List<NearbyMerchantListBean> nearbyMerchantList, Context context) {
        this.nearbyMerchantList = nearbyMerchantList;
        this.context = context;
    }

    public void setNearbyMerchantList(List<NearbyMerchantListBean> nearbyMerchantList) {
        this.nearbyMerchantList = nearbyMerchantList;
    }

    @Override
    public int getCount() {
        return nearbyMerchantList.size();
    }

    @Override
    public Object getItem(int i) {
        return nearbyMerchantList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }
    MyViewHolder viewHolder;
    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view==null)
        {
            view= LayoutInflater.from(context).inflate(R.layout.item_nearmarket_home,null);
            viewHolder=new MyViewHolder();
            viewHolder.imageView= (ImageView) view.findViewById(R.id.iv_picmarket);
            viewHolder. start= (ImageView) view.findViewById(R.id.iv_stars_nearmarket);
            viewHolder.tv_name= (TextView) view.findViewById(R.id.item_shopname_nearmarket);
            viewHolder.tv_marketname= (TextView) view.findViewById(R.id.item_marketname_nearmarket);
            viewHolder.tv_onsale= (TextView) view.findViewById(R.id.item_onsale_nearmarket);
            viewHolder.tvseled= (TextView) view.findViewById(R.id.item_saled_nearmarket);
            view.setTag(viewHolder);
        }
        else {
            viewHolder= (MyViewHolder) view.getTag();
        }
        String pic=nearbyMerchantList.get(i).getPic();
        Glide.with(context).load(pic).into(viewHolder.imageView);
        viewHolder.tv_name.setText(nearbyMerchantList.get(i).getName());
        viewHolder.tv_marketname.setText(nearbyMerchantList.get(i).getMarket_name());
       String oncale=nearbyMerchantList.get(i).getSelling_goods_cnt()+"";
        viewHolder.tv_onsale.setText(oncale);
        String saled=nearbyMerchantList.get(i).getSold_orders_cnt()+"";
        viewHolder.tvseled.setText(saled);
       int score= nearbyMerchantList.get(i).getScore();
        switch (score)
        {
            case 10:
            case 9:
                viewHolder.start.setImageResource(R.mipmap.smallfive);
                break;
            case 8:
            case 7:
                viewHolder.start.setImageResource(R.mipmap.smallfour);
                break;
            case 6:
            case 5:
                viewHolder.start.setImageResource(R.mipmap.smallthree);
                break;
            case 4:
            case 3:
                viewHolder.start.setImageResource(R.mipmap.smalltwo);
                break;
            case 2:
            case 1:
            case 0:
                viewHolder.start.setImageResource(R.mipmap.smallone);
                break;

        }
        return view;
    }
    public class MyViewHolder {
        ImageView imageView,start;
        TextView tv_name,tv_marketname,tv_onsale,tvseled;
    }
}
